﻿

#include <iostream>
#include<list>
#include<stack>
using namespace std;
void TestString1()
{
    //容器读写字符串
    string s1("hello world");
    string s2 = "hello world";
    string::iterator it = s1.begin();
    while (it != s1.end())
    {
        cout << *it ;
        it++;
    }
    cout << endl;
    //容器读写列表
    list<int> lt;
    lt.push_back(1);
    lt.push_back(2);
    lt.push_back(3);
    lt.push_back(4);
    lt.push_back(5);
    /*list<int>::iterator lit = lt.begin();*/
    auto lit = lt.begin();
    while (lit != lt.end())
    {
        cout << *lit<<" ";
        lit++;
    }
   

}

void TestString2()
{
//逆置reverse
    string s1("hello world");
    auto rit = s1.rbegin();
    while (rit != s1.rend())
    {
        cout << *rit << " ";
        rit++;
    }
    
    //读
    for (auto ch : s1)
    {
        cout << ch << "";
    }
    //写
    cout << endl;
    for (auto& ch : s1)
    {
        ch++;
    }
    cout << s1;
}
void func(const string& s)
{
    //正逆写字符串
    //string::const_iterator it = s.begin();
    auto it = s.begin();
    while (it != s.end())
    {
        // 不支持写
        // *it = 'a';

        // 读
        cout << *it << " ";
        ++it;
    }
    cout << endl;

    //string::const_reverse_iterator rit = s.rbegin();
    auto rit = s.rbegin();
    while (rit != s.rend())
    {
        cout << *rit << " ";
        ++rit;
    }
    cout << endl;
}
void TestString3()
{
    string s1("hello worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyy");
    
    //复制s1
    string s2(s1);
    cout <<s2<<endl;
    //片段复制（s1,从s1[6]开始,长度为5的字符串）
    string s3(s1, 6, 5);
    cout << s3 << endl;
    //片段复制（s1,从s1[6]开始,长度为s.size() -6的字符串）
    string s4(s1, 6);
    cout << s4 << endl;
     

    string s6(s1, 6, s1.size() - 6);
    cout << s6 << endl;
    //创建字符串（length，“char”）
    string s7(10,'b');
    cout << s7 << endl;

    string s8(++s7.begin(), --s7.end());
    cout << s8 << endl;
}
void TestString4()
{
    string s1("hello world");
    cout << s1.size() << endl;
    cout << s1.length() << endl;
    cout << s1.capacity() << endl;
    s1.clear();
    s1 += "张三四";
    cout << s1.size() << endl;
    cout << s1.capacity() << endl;
}

int main() 
{
    cout << "Hello World!\n";
    TestString4();
}


